package com.gl.order.commom.util;

import org.apache.commons.lang3.StringUtils;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 流程工具類
 */
public class ProcessCommonUtil {

    //连接
    public static String CONNECTION = " LEFT JOIN #{TABLE_NAME} ON A.ZBWID = ALIAS.id ";
    //別名
    public static String ALIAS = "ALIAS";
    //條件
    public static String CONDITIONS = "CONDITIONS";
    //表名
    public static String TABLE_NAME = "TABLE_NAME";
    //审核
    public static String CZLX_AUDIT = "1";
    //跨节点审核
    public static String CZLX_ACROSS_AUDIT = "2";
    //不通过
    public static String CZLX_NOTPASS = "-1";
    //回退
    public static String CZLX_BACK = "3";
    //跨节点回退
    public static String CZLX_ACROSS_BACK = "4";
    //审核中
    public static String LCZT_AUDIT = "1";
    //通过
    public static String LCZT_PASS = "99";
    //不通过
    public static String LCZT_NOTPASS = "-1";
    //草稿
    public static String LCZT_DRAFT = "0";

    public static List<String> CZLX_LIST = new ArrayList<String>();
    static {
        CZLX_LIST.add(CZLX_AUDIT);
        CZLX_LIST.add(CZLX_ACROSS_AUDIT);
        CZLX_LIST.add(CZLX_NOTPASS);
        CZLX_LIST.add(CZLX_BACK);
        CZLX_LIST.add(CZLX_ACROSS_BACK);
        CZLX_LIST.add(CZLX_AUDIT);
    }
    //WID
    public static String WID = "WID";
    //主表WID
    public static String ZBWID = "ZBWID";
    //流程WID
    public static String LC_WID = "LC_WID";
    //当前状态
    public static String DQZT = "DQZT";
    //到达时间
    public static String DDSJ = "DDSJ";
    //节点WID
    public static String JD_WID = "JD_WID";
    //审核角色
    public static String SH_ROLE = "SH_ROLE";
    //操作类型
    public static String CZLX = "CZLX";
    //审核意见
    public static String SHYJ = "SHYJ";
    //节点状态
    public static String JDZT = "JDZT";
    //审核人
    public static String SHR = "SHR";
    //开始时间
    public static String KSSJ = "KSSJ";
    //结束时间
    public static String JSSJ = "JSSJ";

    public static String START_PROCESS = "START";

    public static String DATE_FORMAT = "yyyy-MM-dd";

    public static String DATE_FORMAT1 = "yyyy-MM-dd HH:mm:ss";

    public static String DATE_FORMAT2 = "yyyy-MM-dd HH:mm:ss SSS";

    /**
     * 审核必填参数
     * @param zbwid 主表id
     * @param lcwid 流程id
     * @param jdwid jdid
     * @param czlx 操作类型
     * @return
     */
    public static Map<String, Object> auditProcessMap(String tableName, String zbwid, String lcwid, String jdwid, String czlx) {
        Map<String, Object> auditMap = new HashMap<>();
        auditMap.put(ProcessCommonUtil.TABLE_NAME, tableName);
        auditMap.put(ProcessCommonUtil.ZBWID, zbwid);
        auditMap.put(ProcessCommonUtil.LC_WID, lcwid);
        auditMap.put(ProcessCommonUtil.JD_WID, jdwid);
        auditMap.put(ProcessCommonUtil.CZLX, czlx);
        return auditMap;
    }

    /**
     * 得獲取當前時間
     * @return
     */
    public static String getCurrDateStr(String format) {
        if (StringUtils.isEmpty(format)) {
            format = DATE_FORMAT2;
        }
        SimpleDateFormat simp = new SimpleDateFormat(format);
        return simp.format(new Date());
    }


    public static Map<String,String> mapToUpperCase(Map<String,String> map) {
        Map<String, String> result = new HashMap<String, String>();
        Set<String> set = map.keySet();
        for (String key : set) {
            String value = map.get(key);
            result.put(key.toUpperCase(), value);
        }
        return result;
    }

    public static List<Map<String,String>> listToUpperCase(List<Map<String,String>> resultList) {
        List<Map<String, String>> result = new ArrayList<Map<String, String>>();
        for (Map<String, String> map : resultList) {
            result.add(mapToUpperCase(map));
        }
        return result;
    }

    /**
     * uuid
     * @return
     */
    public static String uuid(){
        return UUID.randomUUID().toString();
    }

    public static String toString(Object obj){
        if(obj == null){
            return "";
        }
        return obj.toString();
    }
    public static int toInt(Object obj){
        if(obj == null){
            return 0;
        }
        return Integer.parseInt(obj.toString());
    }
}
